package com.game77.guessTheWords2.util.offer;

import java.util.List;

import com.game77.guessTheWords2.MainActivity;
import com.game77.guessTheWords2.R;
import com.game77.guessTheWords2.core.StageManager;
import com.game77.guessTheWords2.scene.ToolShopScene;
import com.mobile.app.adinfo.GESingleInfo;
import com.mobile.app.main.GEInstance;
import com.mobile.app.main.GEListener;

public class GeADHelper implements GEListener {

	public static GeADHelper instance = new GeADHelper();

	private GeADHelper() {
	}

	GEInstance geInstance;

	public void initGE() {
		geInstance = new GEInstance();
		// 初始函数
		geInstance
				.initialize(
						MainActivity.instance,
						"9cd40c5a2a87f36cBpcDUZedl8x5ngt1HJZr0/HfWJyQ4hLqxziRsq9fO0EEOjUb",
						"mumayi");// 每次程序启动只要初始化一次(设置开发者UID和PID)
		geInstance.setTestMode(false);// 开启测试模式(默认是关闭的,测试的时候可以开启,方便调试并查看广告后台错误信息)
		geInstance.setOnGEListener(this);// 继承GEListener接口(1.监听自定义广告数据
											// 2.监听是否获取金币成功)
		geInstance.setNotificationIcon(R.drawable.icon);// 设置状态栏图标
		geInstance.openListAdOn(false);// 是否开启点击任意(自定义广告除外)广告都打开积分墙(默认不开启)

		// 虚拟积分
		geInstance.setSocreUnit("金币");// 设置积分的单位(例如:金币或金蛋或人民币等)
		geInstance.setScoreParam(1);// 设置金币的转换率(例如:如果默认下载一款软件得到的积分是50,若设置转换率为10,则最终显示并赋予用户的积分是50*10=500)
		geInstance.setDefalutScore(0);// 设置给用户的默认积分(如果不设置默认为0)
		GEInstance.setListName("免费获取金币");// 修改积分墙标题名称
	}

	public void loadOfferWall() {
		GEInstance.loadListAd();
	}

	public void loadPush() {
		geInstance.loadPushAd();
	}

	public int getCoin() {
		return geInstance.getScore();
	}

	public void addCoin(int v) {
		geInstance.addScore(v);
	}

	@Override
	public void onAdFailed(String arg0) {
		MainActivity.instance.showTip("金币获取失败，失败原因:" + arg0);

	}

	@Override
	public void onAdSucceed(int arg0) {
		MainActivity.instance.showTip("恭喜你获得" + arg0 + "金币");
		// 直接消费掉
		geInstance.addScore(-arg0);
		// 通知界面获取金币成功，刷新界面
		StageManager.instance.setGoldCount(StageManager.instance.getGoldCount()
				+ arg0);
		ToolShopScene.make().updateCoins();
	}

	public void dispose() {
		GEInstance.unbindService(MainActivity.instance);
	}

	@Override
	public void onDumutipleInfo(List arg0) {
		// TODO Auto-generated method stub

	}

	@Override
	public void onSingleInfo(GESingleInfo arg0) {
		// TODO Auto-generated method stub

	}

}
